/**
 * Created by yananliu on 2017/12/15.
 */
import * as React from 'react';
import {ProductItemComponent} from "../productitem/ProductItemComponent";
import {getProductList} from "../../constant/apis";
import AjaxUtil from "../../util/AjaxUtil";
import {ResponseBean} from "../../bean/ResponseBean";
import {JSONUtil} from "../../util/JSONUtil";
import {ProductVO} from "../../vo/ProductVO";

require('./productListComponent.scss');

export interface Props {
}

interface State {
    productList : Array<ProductVO>
}


export class ProductListComponent extends React.Component<Props>{


    public state : State = {
        productList : []
    };


    componentDidMount(){

        const that = this;

        AjaxUtil.sendRequest(getProductList,{},function (data:any) {

            const res : ResponseBean = JSONUtil.JSONToClass(new ResponseBean(),data);

            that.setState({productList:res.productlist},function () {


            })

        });

    }

    render(){

        return <div className="i-p-group clearfix">
            {
                this.state.productList.map(function (value,index) {

                    return <ProductItemComponent key={value.id} value = {value} theme={'default'} />

                })
            }
        </div>

    }
}
